import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import '@/utils/log-logo.js'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import ElementUI, { Notification } from 'element-ui';
import { APP_NAME, IS_SHOW_AUTH, ELEMENT_LOADING_TEXT, ELEMENT_LOADING_BACKGROUND } from '@/setting'
import 'element-ui/lib/theme-chalk/index.css';
import '@/assets/css/common.css'
import '@/assets/css/iconfont.css'
// 全局 自定义指令  --  1.v-drag
import directive from '@/utils/directive.js'
// 全局 自定义组件
import tian_component from '@/utils/tian_component.js'
Vue.use(directive)
Vue.use(tian_component)
Vue.use(ElementUI)
Vue.config.productionTip = false
Vue.prototype.ELEMENT_LOADING_TEXT = ELEMENT_LOADING_TEXT
Vue.prototype.ELEMENT_LOADING_BACKGROUND = ELEMENT_LOADING_BACKGROUND
Vue.prototype.$Notification = function (message, type, duration) {
  Notification({
    title: "提示",
    message,
    type: type || "warning",
    duration: duration || 1500,
  })
}
router.beforeEach((to, from, next) => {
  NProgress.start();
  if (IS_SHOW_AUTH) {
    document.title = to.meta.title + " - " + APP_NAME;
  } else {
    document.title = to.meta.title;
  }
  if(to.meta.isLogin){
    if(JSON.parse(window.sessionStorage.getItem("musicStorage"))?.user?.userInfo){
      next()
    }else if(!from.name){
      Notification({
        title: "提示",
        message:"请先登录",
        type: "warning",
        duration: 1500,
      })
      router.push("/")
      NProgress.done();
    }else{
      store.dispatch("common/SET_CHANGE_LOGIN_DIALOG")
      Notification({
        title: "提示",
        message:"请先登录",
        type: "warning",
        duration: 1500,
      })
      NProgress.done();
    }
  }else{
    next()
  }
})
router.afterEach((to, from) => {
  NProgress.done();
})
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
